ABC149 D - Prediction and Restriction
提出
WA
code: python
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = input()
ans = 0
for i in range(len(t)):
if (i+1 < k):
ans += p
ans += r
else:
ans += s
else:
pass
else:
ans += p
pass
else:
ans += r
pass
else:
ans += s
print(ans)
解答
code: python
n, k = map(int, input().split())
r, s, p = map(int, input().split())
t = list(input())
ans = 0
# 出した手を保存
for i, t in enumerate(t):
if t == 'r':
command = 'p'
point = p
elif t == 's':
command = 'r'
point = r
elif t == 'p':
command = 's'
point = s
if (i - k >= 0) and (commandsi - k == command): # 手を出してないこととして良い
command = ''
point = 0
ans += point
print(ans)
メモ
提出
AC
code: python
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = input()
hands = []
ans = 0
for i in range(len(t)):
if len(hands) < k or (len(hands) >= k and hands-k != "p"): ans += p
hands.append("p")
else:
hands.append("n")
if len(hands) < k or (len(hands) >= k and hands-k != "r"): ans += r
hands.append("r")
else:
hands.append("n")
if len(hands) < k or (len(hands) >= k and hands-k != "s"): ans += s
hands.append("s")
else:
hands.append("n")
print(ans)